package com.zwh.spring.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.zwh.spring.demo.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public void create(String name, String password, Integer age) {
		jdbcTemplate.update("insert into t_user(name, password, age) values(?,?,?)", name, password, age);
	}

	@Override
	public void deleteByName(String name) {
		jdbcTemplate.update("delete from t_user where name = ?", name);
	}

	@Override
	public Integer getAllUsers() {

		return jdbcTemplate.queryForObject("select count(1) from t_user", Integer.class);
	}

	@Override
	public void deleteAllUsers() {
		jdbcTemplate.update("delete from t_user");
	}

}
